/*
 * KeyTriple.java
 *
 * Created on June 27, 2006, 9:18 PM
 *
 */

package galronnlp.pcfg.parser;

import galronnlp.util.Tuple;
import java.lang.Math;

/**
 * Implementation of a 2-tuple of integers, used to index the Chart.
 *
 * @author Daniel A. Galron
 */
public class KeyDouble extends Tuple {
    
    /** Creates a new instance of KeyTriple */
    public KeyDouble() {
        super(2);
    }
    
    public KeyDouble(Object o1, Object o2) {
        this();
        this.array[0] = o1;
        this.array[1] = o2;
    }
    
    public boolean equals(Object o) {
        KeyDouble other = (KeyDouble)o;
        boolean ret = (((Integer)other.array[0]).intValue() == ((Integer)this.array[0]).intValue()) &&
                      (((Integer)other.array[1]).intValue() ==  ((Integer)this.array[1]).intValue());
        return ret;
    }
    
    public String toString() {
        return "(" + (Integer)this.array[0] + ", " + (Integer)this.array[1] + ")";
    }
    
    public int hashCode() {
        int i1 = ((Integer)this.array[0]).intValue();
        int i2 = ((Integer)this.array[1]).intValue();
        if(i1 < 0)
            return (int)(Math.pow((double)i1, (double)i2) * -1.0);
        else
            return (int)(Math.pow((double)i1, (double)i2));
    }
    
}
